package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.OrderService;
import com.itheima.vo.OrderInfoVo;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 预约订单的控制层
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Reference
    private OrderService orderService;

    /**
     * 提交预约订单数据
     * @param orderInfoVo
     * @return
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody OrderInfoVo orderInfoVo){
        try {
            Integer orderId = orderService.add(orderInfoVo);
            return  Result.success(MessageConstant.ORDER_SUCCESS,orderId);
        } catch (Exception e) {
            e.printStackTrace();
            return  Result.failed(MessageConstant.ORDER_FULL);
        }
    }


    /**
     * 根据预约订单id查询成功预约后的订单信息
     * @param id
     * @return
     */
    @PostMapping("/findAssociateOrderById")
    public Result findAssociateOrderById(Integer id){
        try {
            Map<String, Object> orderInfo = orderService.findAssociateOrderById(id);
            return Result.success(MessageConstant.QUERY_ORDER_SUCCESS,orderInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failed(MessageConstant.QUERY_ORDER_FAIL);
        }
    }

}
